﻿using FineUI;
using SysManage.BLL;
using System;
using ZHDJ.Data.Models.Center;
using ZHDJ.PersonalCenter.BLL;

namespace ZHDJ.PersonalCenter.Module.VolunteerService
{
    public partial class VolunteerActivitieList : PageBase
    {
        #region ViewPower

        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "";
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        #region 数据加载
        private void LoadData()
        {
            // 权限检查
            //CheckPowerWithButton("PartyArticleAdd", btnAdd);

            // 每页记录数
            Grid1.PageSize = ConfigHelper.PageSize;

            BindGrid();
        }

        private void BindGrid()
        {
            var ds = PartyVolunteerActivitie.GetPersonalGridData(Grid1.PageIndex, Grid1.PageSize, txtTitle.Text.Trim(), this.CurrentUser.LoginID, this.BranchID, ddlType.SelectedValue);

            Grid1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
            Grid1.DataSource = ds.Tables[0];
            Grid1.DataBind();
        }

        protected void Grid1_PreDataBound(object sender, EventArgs e)
        {
            // 数据绑定之前，进行权限检查
            //CheckPowerWithWindowField("PartyArticleEdit", Grid1, "editField");
            //CheckPowerWithLinkButtonField("PartyArticleDelete", Grid1, "deleteField");
        }

        protected void Grid1_Sort(object sender, GridSortEventArgs e)
        {
            Grid1.SortDirection = e.SortDirection;
            Grid1.SortField = e.SortField;
            BindGrid();
        }

        protected void ddlGridPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            Grid1.PageSize = Convert.ToInt32(ddlGridPageSize.SelectedValue);
            BindGrid();
        }

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();
        }

        public string GetPeopleCount(object obj)
        {
            return PartyVolunteerActivitie.GetPeopleCountByActivityID(obj.ToString()).ToString() + "人";
        }

        public string GetDetailUrl(object obj)
        {
            return "http://" + Request.Url.Host + "/Portal/VolunteerActivitie/VolunteerActiviteDetail.aspx?ID=" + obj.ToString();
        }
        #endregion

        #region 按钮事件
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindGrid();
        }
        #endregion
    }
}